from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver


class BasePage():
    """
    BasePage提供公共方法的封装，即和页面逻辑无关的封装
    比如解决driver初始化的问题
    """
    # def __init__(self):
    #     # 通过remote复用浏览操作
    #     chrome_arg = webdriver.ChromeOptions()
    #     # 加入调试地址
    #     chrome_arg.debugger_address = "127.0.0.1:9992"
    #     # 实例化driver对象
    #     self.driver = webdriver.Chrome(options=chrome_arg)
    #     # 打开首页
    #     self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index")
    #     self.driver.implicitly_wait(3)

    def __init__(self, base_driver=None):
        if base_driver is None:
            self.executable_path = "C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe"
            # 声明一个变量，设置为chrometoptions
            chrome_opts = webdriver.ChromeOptions()
            # 此处的端口号要与chrome调试模式设置的端口号相同
            chrome_opts.debugger_address = "127.0.0.1:9992"
            self.driver = webdriver.Chrome(executable_path=self.executable_path, options=chrome_opts)
            # 打开首页
            self.driver.get("https://work.weixin.qq.com/wework_admin/frame#index")
            self.driver.implicitly_wait(5)
        else:
            #将self.driver添加一个WebDriver对象注解，解决类型提示的问题
            #是个注解，没有实际作用，只是方便ide操作了
            self.driver: WebDriver = base_driver

